/*
  Copyright (c) 2010
  The Regents of the University of Michigan
  All Rights Reserved

  Permission is granted to use, copy, create derivative works, and
  redistribute this software and such derivative works for any purpose,
  so long as the name of the University of Michigan is not used in
  any advertising or publicity pertaining to the use or distribution
  of this software without specific, written prior authorization. If
  the above copyright notice or any other identification of the
  University of Michigan is included in any copy of any portion of
  this software, then the disclaimer below must also be included.

  This software is provided as is, without representation or warranty
  of any kind either express or implied, including without limitation
  the implied warranties of merchantability, fitness for a particular
  purpose, or noninfringement.  The Regents of the University of
  Michigan shall not be liable for any damages, including special,
  indirect, incidental, or consequential damages, with respect to any
  claim arising out of or in connection with the use of the software,
  even if it has been or is hereafter advised of the possibility of
  such damages.
*/

/* id.h -- functions for dealing with DHT ids. */

#ifndef ID_H
#define ID_H

#include <glib.h>

struct ContactAddress;

#define KEY_SIZE 20

gboolean clearview_id_equal(gconstpointer lhs, gconstpointer rhs);
gint clearview_id_cmp(gconstpointer lhs, gconstpointer rhs, gpointer junk);
char *get_id_distance(const char *id1, const char *id2);
gint clearview_id_shared_prefix_bits(const unsigned char *id1,
                                     const unsigned char *id2);
gint clearview_id_cmp_by_distance(gconstpointer lhs, gconstpointer rhs,
                                  gpointer reference);
gint clearview_cmp_contacts_by_distance(gconstpointer contact1,
                                        gconstpointer contact2,
                                        gpointer reference);
guint clearview_id_hash(gconstpointer key);

// Caller MUST free the returned pointer with clearview_id_free.
char *clearview_id_copy(char *id);

static inline char *clearview_id_new(void) {
  return g_slice_alloc(KEY_SIZE);
}

static inline void clearview_id_free(char *id) {
  g_slice_free1(KEY_SIZE, id);
}

// Caller should NOT free the returned pointer.
char *clearview_get_id(struct ContactAddress *contact);

#endif /* ID_H */
